package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.js.purs.domain.dto.NoticeDto;
import com.js.purs.utils.RemarkUtils;
import io.swagger.models.auth.In;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurBindNotice;
import com.js.purs.service.IPurBindNoticeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 招标公告Controller
 *
 * @author lzq
 * @date 20240627
 */
@RestController
@RequestMapping("/notice")
public class PurBindNoticeController extends BaseController {
    @Autowired
    private IPurBindNoticeService purBindNoticeService;

    /**
     * 查询招标公告列表
     */
    @RequiresPermissions("purs:notice:list")
    @GetMapping("/list")
    public TableDataInfo list(PurBindNotice purBindNotice) {
        startPage();
        List<PurBindNotice> list = purBindNoticeService.selectPurBindNoticeList(purBindNotice);
        return getDataTable(list);
    }

    /**
     * 导出招标公告列表
     */
    @RequiresPermissions("purs:notice:export")
    @Log(title = "招标公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurBindNotice purBindNotice) {
        List<PurBindNotice> list = purBindNoticeService.selectPurBindNoticeList(purBindNotice);
        ExcelUtil<PurBindNotice> util = new ExcelUtil<PurBindNotice>(PurBindNotice.class);
        util.exportExcel(response, list, "招标公告数据");
    }

    /**
     * 获取招标公告详细信息
     */
    @RequiresPermissions("purs:notice:query")
    @GetMapping(value = "/{ntId}")
    public AjaxResult getInfo(@PathVariable("ntId") String ntId) {
        return success(purBindNoticeService.selectPurBindNoticeByNtId(ntId));
    }

    /**
     * 新增招标公告
     */
    @RequiresPermissions("purs:notice:add")
    @Log(title = "招标公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurBindNotice purBindNotice) {
        return toAjax(purBindNoticeService.insertPurBindNotice(purBindNotice));
    }

    /**
     * 修改招标公告
     */
    @RequiresPermissions("purs:notice:edit")
    @Log(title = "招标公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurBindNotice purBindNotice) {
        return toAjax(purBindNoticeService.updatePurBindNotice(purBindNotice));
    }

    /**
     * 删除招标公告
     */
    @RequiresPermissions("purs:notice:remove")
    @Log(title = "招标公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ntIds}")
    public AjaxResult remove(@PathVariable String[] ntIds) {
        return toAjax(purBindNoticeService.deletePurBindNoticeByNtIds(ntIds));
    }

    /**
     * 修改公告发布时间
     */
    @RequiresPermissions("purs:notice:edit")
    @Log(title = "招标公告", businessType = BusinessType.UPDATE)
    @GetMapping("/updateNoticeSendTime/{ntId}")
    public AjaxResult updateNoticeSendTime(@PathVariable("ntId") String ntId) {
        return toAjax(purBindNoticeService.updatePurBindNoticeBySendTime(ntId));
    }

    @GetMapping("/getList")
    public AjaxResult test() {
        return success(purBindNoticeService.selectBindNoticeList());
    }




    @PostMapping("/updateRemark")
    public AjaxResult test2(@RequestParam Map<String, Object> map ) {

        NoticeDto notice = new NoticeDto();
        if (notice != null) {
            if (map.get("remark").toString() != null) {
                notice.setRemark(map.get("remark").toString());
            }
            if (map.get("ntId").toString() != null) {
                notice.setNtId(map.get("ntId").toString());
            }

        }

        return toAjax(purBindNoticeService.updatePurBindNoticeRemark(notice));

    }


}
